package javaLearning.IO集合;

import java.io.*;

/**
 * 读取文件
 *
 * @author : K k
 * @date : 21:52 2020/8/14
 */
public class FileIODemo {
    public static void main(String[] args) {

        File file = new File("D:\\hello.txt");
        // System.out.println(file.getName());
        byte[] b = new byte[1024];
        System.out.println(file.length());

        try (FileInputStream is = new FileInputStream(file)) {
            int i;
            while ((i = is.read(b)) != -1) {
                String s = new String(b, 0, i);
                System.out.println(s);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            System.out.println(b[0]);
        }


        try (FileOutputStream op = new FileOutputStream(file,true);) {
            String r="????asdasdas";
            op.write(r.getBytes());

        } catch (IOException e) {
            e.printStackTrace();
        }
//        String s="hello,world!!";
//        System.out.println(s.getBytes()[0]);
    }
}
